package com.pig4cloud.pig.common.core.constant.enums;

import cn.hutool.core.util.StrUtil;
import com.pig4cloud.pig.common.core.constant.CommonConstants;
import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * @author KonBAI
 * @version 1.0
 * Create by 2020/09/27 11:21
 */
@Getter
@AllArgsConstructor
public enum ResultEnum {

    /**
     * 操作成功
     */
    SUCCESS(CommonConstants.SUCCESS, "操作成功"),
    /**
     * 操作失败
     */
    ERROR(CommonConstants.FAIL, "操作失败"),
    /**
     * 自定义
     */
    CUSTOM(CommonConstants.CUSTOM, "");

    /**
     * 返回码
     */
    private int code;
    /**
     * 返回信息
     */
    private String msg;

    /**
     * 拼接返回消息
     * @param description
     * @return
     */
    public ResultEnum append(String description) {
        if(CommonConstants.SUCCESS.equals(this.code)){
            this.msg = SUCCESS.msg;
        } else if (CommonConstants.FAIL.equals(this.code)) {
            this.msg = ERROR.msg;
        } else {
            this.msg = CUSTOM.msg;
        }
        CUSTOM.code = this.code;
        CUSTOM.msg = this.msg + StrUtil.COMMA + description;
        return CUSTOM;
    }

}
